package com.dkd.manage.controller;

import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.core.page.TableDataInfo;
import com.dkd.common.enums.BusinessType;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.manage.domain.Order;
import com.dkd.manage.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单管理Controller
 *
 * @author hsh
 * @date 2025-02-21
 */
@Api(tags = "订单管理Controller" )
@RestController
@RequestMapping("/manage/order" )
public class OrderController extends BaseController {
	@Autowired
	private IOrderService orderService;
	
	/**
	 * 查询订单管理列表
	 */
	@ApiOperation("查询订单管理列表" )
	@PreAuthorize("@ss.hasPermi('manage:order:list')" )
	@GetMapping("/list" )
	public TableDataInfo list(Order order) {
		startPage();
		List<Order> list = orderService.selectOrderList(order);
		return getDataTable(list);
	}
	
	/**
	 * 导出订单管理列表
	 */
	@ApiOperation("导出订单管理列表" )
	@PreAuthorize("@ss.hasPermi('manage:order:export')" )
	@Log(title = "订单管理" , businessType = BusinessType.EXPORT)
	@PostMapping("/export" )
	public void export(HttpServletResponse response, Order order) {
		List<Order> list = orderService.selectOrderList(order);
		ExcelUtil<Order> util = new ExcelUtil<>(Order.class);
		util.exportExcel(response, list, "订单管理数据" );
	}
	
	/**
	 * 获取订单管理详细信息
	 */
	@ApiOperation("获取订单管理详细信息" )
	@PreAuthorize("@ss.hasPermi('manage:order:query')" )
	@GetMapping(value = "/{id}" )
	public AjaxResult getInfo(@PathVariable("id" ) Long id) {
		return success(orderService.selectOrderById(id));
	}
	
	/**
	 * 新增订单管理
	 */
	@ApiOperation("新增订单管理" )
	@PreAuthorize("@ss.hasPermi('manage:order:add')" )
	@Log(title = "订单管理" , businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody Order order) {
		return toAjax(orderService.insertOrder(order));
	}
	
	/**
	 * 修改订单管理
	 */
	@ApiOperation("修改订单管理" )
	@PreAuthorize("@ss.hasPermi('manage:order:edit')" )
	@Log(title = "订单管理" , businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody Order order) {
		return toAjax(orderService.updateOrder(order));
	}
	
	/**
	 * 删除订单管理
	 */
	@ApiOperation("删除订单管理" )
	@PreAuthorize("@ss.hasPermi('manage:order:remove')" )
	@Log(title = "订单管理" , businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}" )
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(orderService.deleteOrderByIds(ids));
	}
}
